import java.util.*;

public class Work04 {
    static String start;
    static String end;
    static int[] move={3,2,1,-1,-2,-3};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        start = scanner.next();
        end=scanner.next();
        bfs();
    }

    private static void bfs() {
        Queue<Condition> queue=new LinkedList<Condition>();
        int x=start.indexOf("*");
        queue.offer(new Condition(start,0,x));
        HashSet<String> set=new HashSet<String>();
        set.add(start);
        while (!queue.isEmpty()){
            Condition poll = queue.poll();
            if(poll.s.equals(end)){
                System.out.println(poll.step);
                break;
            }

            for (int i = 0; i < 6; i++) {
                int dx= poll.x+move[i];
                if(dx>=0&&dx<start.length()){
                    String newStr=swap(poll.s,poll.x,dx);
                    if(set.add(newStr)){
                        queue.offer(new Condition(newStr, poll.step+1,dx));
                    }
                }
            }
        }
    }

    private static String swap(String s, int x, int dx) {
        char[] chars = s.toCharArray();
        char ch=chars[x];
        chars[x]=chars[dx];
        chars[dx]=ch;
        return new String(chars);
    }
}
class Condition{
    String s;
    int step;
    int x;
    public Condition(String s, int step, int x) {
        this.s = s;
        this.step = step;
        this.x = x;
    }
}
